#include <stdio.h>
#include <string.h>
#include <memory.h>

int myset[1010];

void init(int n)
{
	for (int i = 0; i <= n; ++i)
		myset[i] = -1;
}

int tofind(int n)
{
	if (myset[n] == -1)
		return n;
	return myset[n]=tofind(myset[n]);
}

void merge(int n, int m)
{
	int x = tofind(n);
	int y = tofind(m);
	if (x != y)
	{
		myset[y] = x;
	}
}

int main()
{
	int time;
	int n,t;
	int x, y;
	int count = 0;
	scanf("%d",& time);
	for(int i=0;i<time;++i)
	{		
		scanf("%d %d", &n, &t);
		init(n);
		for(int j=0;j<t;++j)
		{
			scanf("%d %d", &x, &y);			
			merge(x, y);
		}
		count = 0;
		for(int j=1;j<=n;++j)
		{
			if (myset[j] == -1)
				count++;
		}
		printf("%d\n", count);
	}
	return 0;
}